package com.bjsxt;

import java.io.BufferedInputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.FileInputStream;

public class DataInputDemo {
    public static void main(String[] args) {
        DataInputStream dis = null;
        try{
            dis = new DataInputStream(new BufferedInputStream(new FileInputStream("d:/data.txt")));
            //直接读取数据，注意：读取的顺序要与写入的顺序一致，否则不能正确读取数据。
            System.out.println("char: "+dis.readChar());
            System.out.println("int: "+dis.readInt());
            System.out.println("double: "+dis.readDouble());
            System.out.println("boolean: "+dis.readBoolean());
            System.out.println("String: "+dis.readUTF());
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            try{
                if(dis != null ){
                    dis.close();
                }
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }
}
